# OUTPUT_DIRECTORY:
# Path to the Doxygen output directory (where the resulting doc is stored).
# Note: should be the same as your doxyfile's OUTPUT_DIRECTORY
# Example:
#   OUTPUT_DIRECTORY @CMAKE_CURRENT_BINARY_DIR@
#
set(OUTPUT_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@")


# DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:
# Path to the Doxygen output directory (where the resulting archive(s) 
# should be stored).
# 
# Example:
#   DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY @CMAKE_CURRENT_BINARY_DIR@
#
set(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY "@DOC_ARCHIVES_OUTPUT_DIR@")



# CREATE_HTML_TARZ_ARCHIVE RESULTING_HTML_TARZ_ARCHIVE_FILE:
# Create a compressed (gzip) tar archive of the html directory (located
# under the DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY), and name of the 
# resulting archive file.
# Note: your doxyfile should be configured to enable HTML creation 
#       (using GENERATE_HTML   YES)
# 
# Example: 
#   CREATE_HTML_TARZ_ARCHIVE ON
#   RESULTING_HTML_TARZ_ARCHIVE_FILE ${OUTPUT_DIRECTORY}/${PROJECT_NAME}-html.tar.gz
#
set(CREATE_HTML_TARZ_ARCHIVE 
  @DOC_COMPRESSED_IN_TARGZ@
  )
set(HTML_TARZ_ARCHIVE_FILE 
  @DOC_ARCHIVES_OUTPUT_DIR@/@PROJECT_NAME@-html.tar.gz
  )


set(DOC_DIR_TO_PARSE @DOC_DIR_TO_PARSE@)
message("DOC_DIR_TO_PARSE: @DOC_DIR_TO_PARSE@")

# ----------------------------------------------------------------------------
# Generate documentation

execute_process(
  COMMAND "@DOXYGEN_EXECUTABLE@" "${OUTPUT_DIRECTORY}/Doxyfile.txt"
  WORKING_DIRECTORY ${OUTPUT_DIRECTORY}
  RESULT_VARIABLE errors
  )

if(errors)
  message(FATAL_ERROR "error: Failed to generate documentation")
endif()

# ----------------------------------------------------------------------------
# Create the *.tar.gz file

#step(1 "build *.tar.gz file")
if(CREATE_HTML_TARZ_ARCHIVE)
  if(NOT HTML_TARZ_ARCHIVE_FILE STREQUAL "")
    file(REMOVE "HTML_TARZ_ARCHIVE_FILE")
    execute_process(COMMAND ${CMAKE_COMMAND} -E tar cfz ${HTML_TARZ_ARCHIVE_FILE} html
      WORKING_DIRECTORY ${OUTPUT_DIRECTORY}
      RESULT_VARIABLE errors
      )
    if(EXISTS ${HTML_TARZ_ARCHIVE_FILE})
      message(STATUS "info: created '${HTML_TARZ_ARCHIVE_FILE}'")
    else()
      message(STATUS "warning: could not create '${HTML_TARZ_ARCHIVE_FILE}'")
    endif()
  endif()
endif()
